#!/usr/bin/env perl

use Sys::Hostname;

my $hostname = hostname();
my $ostype;

if ($ =~ /MSWin32/) {
    $ostype = "winsys";
} else {
    $ostype = "unixsys";
}
BEGIN {push @INC, "./lib";}

require "$ostype.pm";
require "$hostname.pm";

my $config = new $hostname;
my $os     = new $ostype;

my $lt = '&lt;';
my $gt = '&gt;';

my %tablehash = (

    activetestimage   =>
        'each row provides information on images currently running on '.
        'smoketest machines',
    authtable         =>
        'each row stores an ip address for machines granted administrative '.
        'privelages',
    buildservers      =>
        'each row stores information for each machine defined as a '.
        'buildserver using CABIE',
    changes           =>
        'each row stores changes from cm systems associated with a '.
        'particular build',
    comments          =>
        'each row can store text associated for a particular build',
    configuration     =>
        'each row stores configuration for a unique job defined on the '.
        'buildserver',
    joblog            =>
        'each row stores log information for each step executed by a '.
        'defined job',
    jobs              =>
        'each row stores collected information for each completed job '.
        'defined on the buildsrever',
    locktest          =>
        'each row acts as a semaphore locking the smoketest server while '.
        'it is executing smoketests',
    monitorservers    =>
        'each row stores port information for the thread running the '.
        'monitorserver',
    pending           =>
        'each row stores files that are pending update for a defined build',
    polltest          =>
        'reserved for future use',
    proctree          =>
        'each row stores process ids for each active build',
    promotion         =>
        'each row stores job information for jobs promoted to a test state',
    removed           =>
        'each row stores job information for job output removed by the '.
        'buildserver',
    restore           =>
        'each row stores backup job information for currently executing builds',
    results           =>
        'each row stores smoke test results for tested jobs',
    run               =>
        'each row stores running data for currently active smoketest sessions',
    semaphores        =>
        'each row acts as a semaphore locking a defined job while it is '.
        'executing on a buildserver',
    serverids         =>
        'each row stores the process id of the running buildserver/monitor',
    stage             =>
        'each row acts as a staging area for jobs that have completed '.
        'building and are awaiting smoketest',
    subscription      =>
        'each row stores email addresses for those interested in receiving '.
        'email about a particular named job',
    testconfiguration =>
        'each row stores configuration for a unique smoketest defined on the buildserver',
    serverid          =>
        'each row stores information about the buildserver including '.
        'the process id of active servers',
    testserver        =>
        'each row stores information about active test servers allowing '.
        'remote restarts of servers that have failed somketests',
    teststate         =>
        'each row stores information about tests being performed or '.
        'completed.',

);

my %fields = (

    "activetestimage:server" => 
        'server the smoketests will be executed from, does not need to be '.
        'the same as deployserver',
    "activetestimage:deployserver" => 
        'the name of the target server for installation or deployment',
    "activetestimage:imagename" => 
        'the name of the raw OS image deployed onto the smoketest server',
    "activetestimage:title" => 
        'the name or title of the individual smoketest',
    "activetestimage:buildserver" => 
        'the name of the buildserver where the build job originated',
    "activetestimage:jobname" => 
        'the name of the build job as found on the buildserver',
    "activetestimage:job" => 
        'the unique ID of the job as found on the buildserver',
    "activetestimage:installimage" => 
        'the name of the image to be installed on the raw OS image',
    "activetestimage:imagereference" => 
        'the name of a configuration file which may be used to deploy the '.
        'raw OS image',
    "authtable:server" => 
        'the name of the buildserver for which authorization is requested',
    "authtable:machine" => 
        'the name or ip address of the machine to be authorized by the '.
        'buildserver',
    "buildservers:server" => 
        'the name of the machine the buildserver is running on',
    "buildservers:description" => 
        'a description of the sw/hw the buildserver is running on ala uname -s',
    "buildservers:port" => 
        'the port number the build server is listening on',
    "buildservers:status" => 
        'the current state of the buildserver (0 or 1)',
    "buildservers:globalmail" => 
        'whether or not to deliver global email for all failed builds',
    "changes:server" => 
        'the name of the machine the buildserver is running on',
    "changes:title" => 
        'the name of the build job running on the buildserver',
    "changes:job" => 
        'the unique ID of the job titled &lt;title&gt; completed on the '.
        'buildserver',
    "changes:changes" => 
        'each entry identifies the change made for &lt;job&gt; on '.
        '&lt;server&gt; for &lt;title&gt;',
    "comments:server" => 
        'the name of the machine the buildserver is running on',
    "comments:title" => 
        'the name of the build job running on the buildserver',
    "comments:job" => 
        'the unique ID of the job titled &lt;title&gt; completed on the '.
        'buildserver',
    "comments:comment" => 
        'a string containing any comment made for &lt;job&gt; on '.
        '&lt;server&gt; for &lt;title&gt;',
    "configuration:server" => 
        'the name of the buildserver the build job is defined to run on',
    "configuration:title" => 
        'the title of the build job running on the buildserver',
    "configuration:port" => 
        'the port associated with the CM system where the source for the '.
        'build job is to be found',
    "configuration:client" => 
        'the client name (perforce) or modules (CVS) that are to be accessed '.
        'for the build job',
    "configuration:top" => 
        'the top level directory name where the source for the build job '.
        'will reside',
    "configuration:type" => 
        'the type of build job - retail, debug, or both (literally)',
    "configuration:toolsdir" => 
        'the path used to locate the tools used for the build job',
    "configuration:isimake" => 
        'unused, set to no',
    "configuration:keeplevel" => 
        'used to determine the number of completed jobs to save before removal',
    "configuration:comment" => 
        'used for the description of a build job',
    "configuration:sccs" => 
        'used to determine the CM system used for the build job (cvs or '.
        'perforce)',
    "configuration:browserlink" => 
        'used to generate a browserlink to the appropriate CM tool, '.
        'currently tested with CVSWEB and P4Web',
    "configuration:state" => 
        'used to determine whether or not the build job is accessable '.
        '(0 = visible, 1 = not visible)',
    "configuration:spam" => 
        'used to determine whether or not to send spam on broken builds '.
        'to globally defined group (in hostname.cm)',
    "configuration:buildsize" => 
        'used to determine how much diskspace a build job requires for '.
        'completion',
    "joblog:server" => 
        'the name of the buildserver the build job is defined on',
    "joblog:title" => 
        'the title of the build job running on the buildserver',
    "joblog:message" => 
        'a message describing the current step in a build while running '.
        '(must have (retail) or (debug) in the string)',
    "joblog:step" => 
        'the step which corrleates with the genweb interface used to '.
        'determine the color supplied as the background',
    "jobs:server" => 
        'the name of the buildserver the build job is defined on',
    "jobs:title" => 
        'the title of the build job as defined on the buildserver',
    "jobs:job" => 
        'the unique id of the build job completed running on the buildserver',
    "jobs:start" => 
        'the start time of the build job completed on the buildserver in '.
        'unix format $os->_get_time())',
    "jobs:end" => 
        'the completion time of the build job completed on the buildserver '.
        'in unix format $os->_get_time())',
    "jobs:status" => 
        'the completion status for the completed job on the buildserver '.
        '(0 = untested, 1 = failed test, 2 = failed build, 3 = passed test, '.
        '8 = failed unit tests, 4-7 reserved for active build states)',
    "jobs:info" => 
        'currently used by CVS only in determining the last check in, into '.
        'the completed job',
    "jobs:sccs" => 
        'used to preserve the CM system used for a completed job in case '.
        'the CM system is replaced',
    "jobs:browserlink" => 
        'used to preserve the CM browser link of a completed job in case '.
        'the CM browser is replaced',
    "jobs:buildsize" => 
        'used to preserve the amount of disk space occupied by a completed '.
        'job, averaged to determine disk usage',
    "jobs:port" => 
        'used to preserve the port for the CM system used for a completed '.
        'build in case the CM system is replaced',
    "jobs:removed" => 
        'used to indicate the a job has been removed automatically by the '.
        'buildserver',
    "jobs:releaseformat" => 
        'used to describe the buildnumber of the job if formatting was '.
        'changed via the systemname.pm file',
    "locktest:server" => 
        'the name of the testserver the smoketest image is deployed to',
    "locktest:title" => 
        'the title smoketest job being deployed to the testserver',
    "locktest:buildjob" => 
        'the title:unique_id of the job being deployed to the testserver',
    "monitorservers:server" => 
        'the name of the machine the monitor server (secondary port to the '.
        'build server) is running on',
    "monitorservers:port" => 
        'the port number the monitor server (secondary port to the build '.
        'server) is listening on',
    "monitorservers:status" => 
        'the current state of the buildserver (0 or 1)',
    "pending:server" => 
        'the name of the machine the build server is running on',
    "pending:title" => 
        'the title of the build job defined on the buildserver',
    "pending:changes" => 
        'a pending list of files to be updated when the next build job is '.
        'executed',
    "polltest:server" => 
        'reserved for future use',
    "polltest:title" => 
        'reserved for future use',
    "proctree:server" => 
        'the name of the machine the build server is running on',
    "proctree:title" => 
        'the title of the build job defined on the buildserver',
    "proctree:job" => 
        'the unique id of the build job currently running on the buildserver',
    "proctree:cmd" => 
        'the cmd execd for the build job on the buildserver',
    "proctree:pid" => 
        'the pid for the execd command running for the build job on the '.
        'buildserver',
    "promotion:server" => 
        'the name of the machine the buildserver is running on',
    "promotion:title" => 
        'the title of the promoted build job built on the buildserver',
    "promotion:job" => 
        'the unique id of the build job promoted on the buildserver',
    "promotion:at" => 
        'the time in unix time format when the build job was promoted on '.
        'the buildserver',
    "promotion:bywhom" => 
        'the ip address of the machine that promoted the build job on the '.
        'buildserver',
    "promotion:comment" => 
        'comment used to describe why the build was promoted',
    "removed:server" => 
        'the name of the machine the buildserver is running on',
    "removed:title" => 
        'the title of the build job output targeted for removal from the '.
        'buildserver',
    "removed:job" => 
        'the unique id of the build job output targeted for removal from '.
        'the buildserver',
    "removed:at" => 
        'the time in unix format when the attempted removal of the build '.
        'job output from the buildserver occured',
    "removed:action" => 
        'the time in unix format when the attempted removal of the build '.
        'job output from the buildserver occured',
    "removed:directory" => 
        'the directory name of the where build job output exists when the '.
        'removal is attempted',
    "restore:server" => 
        'the name of the machine the current build job is running on',
    "restore:title" => 
        'the title of the build job currently running on the buildserver',
    "restore:message" => 
        'a string indicating the job state of the build job currently '.
        'running on the buildserver',
    "restore:time" => 
        'time in unix time format for the start of the build job currently '.
        'running on the buildserver',
    "restore:state" => 
        'the step which corrleates with the genweb interface used to '.
        'determine the color supplied as the background',
    "results:server" => 
        'the name of the server that smoketests, ui tests etc. were '.
        'executed on',
    "results:deployserver" => 
        'the name of the server that the install image was installed on',
    "results:title" => 
        'the title of the smoketest installation',
    "results:buildserver" => 
        'the name of the buildserver the installed job originated from',
    "results:jobname" => 
        'the name of the build job on the buildserver that created the '.
        'installation',
    "results:job" => 
        'the unique ID of the build job on the buildserver that created '.
        'the installation',
    "results:start" => 
        'the time in unix time format when the smoketest installation started',
    "results:end" => 
        'the time in unix time format when the smoketest installation ended',
    "results:teststatus" => 
        'the integer results of the smoketest (not defined currently)',
    "run:server" => 
        'the name of the server that smoketests, ui tests etc. are to be '.
        'executed on',
    "run:deployserver" => 
        'the name of the server that the install image will be installed on',
    "run:title" => 
        'the title of the smoketest installation',
    "run:buildserver" => 
        'the name of the buildserver the installing job originated from',
    "run:jobname" => 
        'the name of the build job on the buildserver that created the '.
        'installation',
    "run:job" => 
        'the unique ID of the build job on the buildserver that created '.
        'the installation',
    "run:start" => 
        'the time in unix time format when the smoketest installation started',
    "run:end" => 
        'the time in unix time format when the smoketest installation ended',
    "run:state" => 
        'the current state of the smoketest deployment machine (currently '.
        'unused)',
    "run:message" => 
        'text message indicating the step currently executing for the '.
        'smoketest installation',
    "run:dependserver" => 
        'the name of any server this smoketest server may have to wait for',
    "semaphores:server" => 
        'the name of the machine the current build job is running on',
    "semaphores:title" => 
        'the title of the build job currently running on the buildserver',
    "semaphores:message" => 
        'a string indicating the job state of the build job currently '.
        'running on the buildserver',
    "semaphores:time" => 
        'time in unix time format for the start of the build job currently '.
        'running on the buildserver',
    "semaphores:state" => 
        'the step which corrleates with the genweb interface used to '.
        'determine the color supplied as the background',
    "serverids:server" => 
        'the name of the running buildserver/monitorserver',
    "serverids:type" => 
        'the type of server (server|monitor)',
    "serverids:pid" => 
        'the process id of the running server (NA on Windows)',
    "stage:server" => 
        'the name of the server that smoketests, ui tests etc. are to be '.
        'executed on',
    "stage:deployserver" => 
        'the name of the server that the install image will be installed on',
    "stage:imagename" => 
        'the name of the raw OS image deployed onto the smoketest server',
    "stage:bootscript" => 
        'the name of the bootscript run on a freshly deployed OS image',
    "stage:title" => 
        'the title of the smoketest installation',
    "stage:buildserver" => 
        'the name of the buildserver the installing job originates from',
    "stage:jobname" => 
        'the name of the build job on the buildserver that created the '.
        'installation media',
    "stage:job" => 
        'the unique ID of the build job on the buildserver that created '.
        'the installation',
    "stage:state" => 
        'the current state of the smoketest deployment machine (currently '.
        'unused)',
    "stage:installimage" => 
        'the name of the image to be installed onto the raw OS image',
    "stage:attempt" => 
        'the number of attempts that may be required to get the image to '.
        'be installed onto the raw OS image',
    "stage:dependserver" => 
        'the name of any server this smoketest server may have to wait for',
    "subscription:server" => 
        'the name of the machine the buildserver is running on',
    "subscription:title" => 
        'the title of the build job for which email subscription is requested',
    "subscription:address" => 
        'the email address which would like email notification upon '.
        'completion of build job running on buildserver',
    "testconfiguration:server" => 
        'the name of the server that smoketests, ui tests etc. are to be '.
        'executed on',
    "testconfiguration:title" => 
        'the title of the smoketest installation',
    "testconfiguration:type" => 
        'the type of install that is being performed as int matched with '.
        'type in environment',
    "testconfiguration:imagename" => 
        'the name of the raw OS image deployed onto the smoketest server',
    "testconfiguration:bootscript" => 
        'the name of the bootscript run on a freshly deployed OS image',
    "testconfiguration:comment" => 
        'used for the description of a smoketest job',
    "testconfiguration:state" => 
        'used to determine whether or not the smoketest is active (0 = '.
        'active, 1 = inactive)',
    "testconfiguration:nextjob" => 
        'unused at this time',
    "testconfiguration:spam" => 
        'unused at this time',
    "testconfiguration:buildjob" => 
        'buildserver:title of job running on buildserver associated with '.
        'this smoketest job',
    "testconfiguration:deployto" => 
        'the target machine for the image to be deployed to',
    "testconfiguration:platform" => 
        'the target platform for which the image is compatible (w2k, sol, '.
        'linux)',
    "testconfiguration:imageserver" => 
        'the server where a virtual image resides for deployment of a '.
        'clean OS to the deployto box',
    "testconfiguration:imagereference" => 
        'the name of a configuration file which may be used to deploy the '.
        'raw OS image onto deployto',
    "testconfiguration:attempts" => 
        'the number of attempts that may be required to get the image to '.
        'be installed onto the raw OS image',
    "testconfiguration:dependserver" => 
        'the name of any server the deployto server may have to wait for',
    "teststate:title" => 
        'the title of the smoketest as defined in testconfiguration',
    "teststate:buildserver" => 
        'the buildserver where the build job was run',
    "teststate:jobname" => 
        'the name of the build job run on the buildserver',
    "teststate:job" => 
        'the job number of the build job run on the buildserver',
    "teststate:step" => 
        'the name of the teststep run or running',
    "teststate:state" => 
        'the state of the teststep run or running. 0=idle, 1=running, '.
        '2=passed 3=failed',
    "teststate:start" => 
        'the start time of the teststep run or running',
    "teststate:end" => 
        'the end time of the teststep run',
    "testserver:server" => 
        'the name of the testserver',
    "testserver:state" => 
        'the state of the testserver.  1=running or waiting for imaging, '.
        '0=unhappy. If the testserver is unhappy it will not reimage and '.
        'will require running build testserver -f servername',

);

my %summary = (

    "activetestimage" =>
        "<strong>smoketest</strong>:  &nbsp;&nbsp;Maybe used for semaphore ".
        "operations on active smoketest deployments.  Currently used to ".
        "determine string substitution in the imagereference for the next ".
        "active OS image to be deployed.",
    "authtable" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Used for adding or removing ".
        "machines from an authorized list providing additional commands.<br>".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt authorize<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt unauthorize<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt authorized<br>",
    "buildservers" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Initialized by starting ".
        "the buildserver (buildserver -s port -m port -d).<br>".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt servers<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt sysinfo<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt shutdown<br>",
    "changes" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Populated by the ".
        "the build command upon the completion of a build job.<br>".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt build<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt notify<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt changes<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt changed<br>",
    "comments" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Populated by shared ".
        "scripts (buildfuncs.pl, gencomments) looking for bug numbers ".
        "in file or change logs<br>".
        "<br>Associated web applications:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt genweb<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt gencomments<br>",
    "configuration" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Populated by createjob ".
        "initially.  Contains charastics for each job defined on the ".
        "buildserver.<br>".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt createjob<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt clone<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt describe<br>",
    "joblog" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Populated by build ".
        "command. Contains current state of a running build<br>".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt jobstate<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt joblog<br>",
    "jobs" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Populated by build ".
        "command. Collects data from all jobs active on the buildserver<br> ".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt runstats<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt genweb<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt xmldump<br>",
    "locktest" =>
        "<strong>smoketest</strong>:  &nbsp;&nbsp;Maybe used for semaphore ".
        "operations on active smoketest deployments.  Currently used to ".
        "lock a smoketest machine from redeployment of an image.",
    "monitorservers" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Initialized by starting ".
        "the buildserver (buildserver -s port -m port -d). This port is used ".
        "in association with a thread that polls the CM system for ".
        "changes<br>".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt nextjob<br>",
    "pending" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;This table is populated ".
        "by the thread utilizing the monitorserver port. When a job is ".
        "executing, and new changes are pending this will show up in the ".
        "genweb page as a star noting that additional files require updating ".
        "<br>".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;<strong>NONE</strong><br>",
    "polltest" =>
        "<strong>smoketest</strong>:  &nbsp;&nbsp; Currently unused",
    "proctree" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp; Used to track all ".
        "process id's that have been forked using internal ".
        "\$os->forkprocess calls. Tracks only calls for which a wait was ".
        "set. Clears out ids when the wait has completed." .
        "<br>Currently internal.<br>",
    "promotion" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp; Used to track jobs that".
        "have been promoted by the build administrator.".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt promote<br>",
    "results" => 
        "<strong>testserver</strong>:  &nbsp;&nbsp;Initialized by a completed ".
        "testserver.  Records are copied from the run table to the results ".
        "table.".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt teststatus -c<br>",
    "removed" => 
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Tracks build jobs removed ".
        "automatically based upon the keep level",
    "restore" => 
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Initialized by a running ".
        "build.  Duplicates information from the semaphores table for a ".
        "running job.  Used to recover active information in case the ".
        "enable command is accidently performed on a running job.".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt recover<br>",
    "run" => 
        "<strong>testserver</strong>:  &nbsp;&nbsp;Initialized by a running ".
        "testserver.  Records are copied from the stage table to the run ".
        "table.".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt teststatus -r<br>",
    "semaphores" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Initialized by running ".
        "a build, or by enabling/disabling a build".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt jobstate<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt disable<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt enable<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt recover<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt build<br>",
    "serverids" =>
        "<strong>buildserver</strong>:  &nbsp;&nbsp;Initialized by starting ".
        "the buildserver (buildserver -s port -m port -d)".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt getid<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt shutdown<br>",
    "stage" =>
        "<strong>testserver</strong>: Stores information about completed ".
        "builds that are ready for testing.  Allows builds to  ".
        "continue on while testservers work on previous builds.".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt teststatus -p<br>",
    "subscription" =>
        "<strong>buildserver</strong>: Stores email addresses of those ".
        "who may be interested in build output information via email ".
        "<br>Associated buildserver commands:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt subscribers<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt subscribe<br>",
    "testconfiguration" =>
        "<strong>smoketest</strong>:  &nbsp;&nbsp;Stores ".
        "information about testservers their images, configuration files, ".
        "bootscripts etc.",
    "testserver" =>
        "<strong>smoketest/buildserver</strong>:  &nbsp;&nbsp;Stores ".
        "information about active testservers and their states ".
        "which can be accessed via the buildserver while tests are running".
        "<br>Associated buildserver command:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt testserver<br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$lt testserver -f servername<br>",
    "teststate" =>
        "<strong>smoketest</strong>:  &nbsp;&nbsp;Stores ".
        "information about testservers and their current tests ".
        "which can be accessed via the buildserver while tests are running ".
        "<br>Associated buildserver command:<br><br>".
        "&nbsp;&nbsp;&nbsp;&nbsp;$gt xmldump<br>",
);


print <<EOF;
content-type: text/html

<html>
<head></head>
<body>
<h1>CABIE Database Schema</h1>
<blockquote>
<table class="table" frame="border" rules="all">
<colgroup>
<col width="14%" />
<col width="86%" />
</colgroup>
<thead valign="bottom">
<tr>
<th>Table</th>
<th>Description</th>
</tr>
</thead>
<tbody valign="top">

EOF

$sqlquery = "show tables";

@sqlarray = $os->run_sql_query($sqlquery, ",");

foreach $line (@sqlarray) {
    print "<tr>\n";
    print "<td><a href=\"#$line"."_reference\">$line</a></td>\n";
    print "<td>$tablehash{$line}</td>\n";
    print "</tr>\n";
}

print <<EOF;
</tbody>
</table>
</blockquote>
<div class="section" id="schema-text-description">
<h1><a name="schema-text-description">Schema: Text Description</a></h1>

<p>This outlines all of the tables and rows currently associated with CABIE. 
The tables which are designated as <strong>buildserver</strong> tables are 
required for the correct operation of CABIE.  Those denoted as 
<strong>smoketest</strong> are used by defined smoketest jobs which are 
currently quite custom and are not distributed with CABIE.  The tables are 
there however and may be used for custom applications.</p>
<p>The commands used by CABIE to populate or manipulate tables are also 
supplied along with the summary descriptions at the head of each table.  '&lt;' 
denotes the command as input to CABIE,  '&gt;' denotes the command as 
output to CABIE</p>
EOF
foreach $line (@sqlarray) {
    print "<div class=\"section\" id=\"$line"."_reference\">\n";
    print "<h2><a name=\"$line"."_reference\">$line table: $line descriptions</a></h2>\n";
print <<EOF;
<p>$summary{$line}</p>
<blockquote>
<table class="table" frame="border" rules="all">
<colgroup>
<col width="26%" />
<col width="15%" />
<col width="59%" />
</colgroup>
<thead valign="bottom">
<tr><th>Field</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody valign="top">
EOF
    $newquery = "describe $line";
    @newarray = $os->run_sql_query($newquery, ",");
    print "<b>Table $line Structure:</b>\n";
    foreach $entry (@newarray) {
        my ($name, $type, $null) = split (/,/, $entry);
        my $field = "$line:$name";
        print "<tr>\n";
        print "<td>$name</td>\n";
        print "<td>$type</td>\n";
        print "<td>$fields{$field}</td>\n";
        print "</tr>\n";
    }
print <<EOF;
</tbody>
</table>
</blockquote>
</div>
EOF
}

print "</body>\n";
print "</html>\n";
